<!DOCTYPE html>
<html class="Content">
<head>
    <title>xUnit.js: Using Mocks</title>
    <link type="text/css" rel="Stylesheet" href="../../Style/documentation.css" />
</head>
<body>
    <h1>Using Mocks</h1>
    <p>
        This example is based on <em>Examples/Tests/Mocks and Stubs/MockTests.js</em> 
    </p>
    <p>
        Many browsers provide a DOM implementation, and typically include objects such as <strong>window</strong>, <strong>document</strong>, and <strong>XMLHttpRequest</strong>.
        While some console host environments might provide analogues to these, situations arise in which objects will either not exist, or need to be temporarily modified in order
        to maintain boundary control.
    </p>
    <h3>Test:</h3>
    <p>
        <span class="Code">
Function.RegisterNamespace("Test");

[Fixture]
Test.MockTests=function(){
	[Fact]
	function MocksWindowReferenceOnHost(){
		var expected="expected";
		var mockWindow=Mocks.GetMock(Object.Global(), "window", expected);
		var actual=null;
		
		mockWindow(function(){
			actual=window;
		});
			
		Assert.Equal(expected, actual);
	}
}            
        </span>
    </p>
    <p>
        In this example, we override the (usually undefined) reference to <em>window</em> on the global <em>this</em> object, provided by the Object.Global() method, with our well-known
        expectation. For the purpose of this test, we don't even care about the shape of the object, just that the reference is set to our expectation.
    </p>
</body>
</html>